package android.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import winkyle.woodenfish.android.service.MessageInfoService;
import winkyle.woodenfish.dao.MessageInfoDao;
import winkyle.woodenfish.model.dto.MessageDto;
import winkyle.woodenfish.model.po.MessageInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author winkyle
 * @date 2018/06/22
 * @description 消息信息业务接口层的实现类
 */
@Service
public class MessageInfoServiceImpl implements MessageInfoService{
	
	@Autowired
	private MessageInfoDao messageInfoDao;

	@Override
	public List<MessageDto> findMessageInfoByUserId(String userId,int page) {
		Pageable pageable = new PageRequest(page-1,10);
		List<MessageInfo> messageInfos = messageInfoDao.findByUserId(userId,pageable);
		List<MessageDto> messageDtos = new ArrayList<MessageDto>();
		for (MessageInfo messageInfo : messageInfos) {
			MessageDto messageDto = new MessageDto();
			messageDto.setTitle(messageInfo.getTitle());
			messageDto.setContent(messageInfo.getContent());
			messageDto.setImageUrl(messageInfo.getImageUrl());
			messageDto.setDescription(messageInfo.getDescription());
			messageDto.setLinkAddress(messageInfo.getLinkAddress());
			messageDto.setUpdateTime(messageInfo.getUpdateTime());
			messageDtos.add(messageDto);
		}
		return messageDtos;
	}
	
	

}
